import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';

export async function GET(request: NextRequest) {
  try {
    const url = new URL(request.url || 'http://localhost');
    const tokenId = url.searchParams.get('tokenId');
    const limit = parseInt(url.searchParams.get('limit') || '50');

    const where = tokenId ? { tokenId } : {};

    const trades = await prisma.trade.findMany({
      where,
      include: {
        token: true
      },
      orderBy: {
        createdAt: 'desc'
      },
      take: limit
    });

    return NextResponse.json(trades);
  } catch (error) {
    console.error('获取交易记录失败:', error);
    return NextResponse.json({ error: '获取交易记录失败' }, { status: 500 });
  }
}
